﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace PSI.Filters {
    /// <summary>
    /// 过滤器，判断用户是否登录，如果没有登录则跳转到登录页面
    /// </summary>
    public class NeedLoginAttribute : ActionFilterAttribute {
        public override void OnActionExecuting(ActionExecutingContext filterContext) {
            if (!PSI.Services.UserService.IsLogin) {
                var returnURL = filterContext.HttpContext.Request.Url.ToString();
                filterContext.HttpContext.Response.Redirect("/User/Login?returnURL=" + returnURL);
            } else {
                base.OnActionExecuting(filterContext);
            }
        }
    }
}